This forum is closed to new posts and
responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:
I have an agent in Java that parse XML files in a Body field, creating Notes documents based on the content of the XML file.
I can read the Nodes values, but not the attributes. What code needs to be added to read attributes of a Node? Code below works fine, except reading attr. (As I'm bad at Java I have no idea how to)
example of attribute is currency below:
<Total currency="USD"></Total>
// (Your code goes here)
Database db=agentContext.getCurrentDatabase();
//get reference to documents with xml attachments
DocumentCollection collection=agentContext.getUnprocessedDocuments();
Document doc=collection.getFirstDocument();
while(doc!=null)
{
RichTextItem body=(RichTextItem)doc.getFirstItem("Body");
//get reference to xml attachment
Vector objects=body.getEmbeddedObjects();
for (int i = 0; i < objects.size() ; i++)
{
EmbeddedObject emo = (EmbeddedObject)objects.get(i);
if(emo.getType()==EmbeddedObject.EMBED_ATTACHMENT)
{
//parse xml attahcment and create dom Document object
org.w3c.dom.Document document=emo.parseXML(false);
//get reference to root element SalesOrder
org.w3c.dom.Element rootElement=document.getDocumentElement();
//get reference to order child nodes
org.w3c.dom.NodeList orders=rootElement.getElementsByTagName("Order");
for(int j=0; j < orders.getLength(); j++)
{
org.w3c.dom.Node order=orders.item(j);
//create notes order document
Document orderDoc=db.createDocument();
orderDoc.replaceItemValue("Form", "Order");
//get reference to all order details: order id, item and quantity
org.w3c.dom.NodeList orderDetails=order.getChildNodes();
for(int k=0; k < orderDetails.getLength(); k++)
{
//replace field values with order details
org.w3c.dom.Node orderDetail=orderDetails.item(k);
if(orderDetail.getNodeName().equals("Id"))
orderDoc.replaceItemValue("OrderId", orderDetail.getFirstChild().getNodeValue());
else if(orderDetail.getNodeName().equals("Item"))
orderDoc.replaceItemValue("Item", orderDetail.getFirstChild().getNodeValue());
else if(orderDetail.getNodeName().equals("Quantity"))
orderDoc.replaceItemValue("Quantity", orderDetail.getFirstChild().getNodeValue());
}